﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CI.Domain.Models;

namespace CI.Presentation.Web.Controllers
{
    public class PacienteController : Controller
    {
        [HttpGet]
        public ActionResult SearchPaciente(string dni, string nombres)
        {
            DomainModelContext dataContext = new DomainModelContext();
            //buscar
            var pacientes = from p in dataContext.vwPaciente
                            where p.numDocumento == dni.Trim() || p.nombres.Contains(nombres.Trim())
                            select p;

            return Json(pacientes.ToList(), JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public ActionResult GetPaciente(string dni)
        {
            DomainModelContext dataContext = new DomainModelContext();
            //buscar
            var paciente = from p in dataContext.Paciente
                            where p.numDocumento == dni.Trim()
                            select p;

            return Json(paciente.SingleOrDefault(), JsonRequestBehavior.AllowGet);
        }
    }
}